package com.leinao.file.controller;

import com.alibaba.fastjson.JSON;
import com.leinao.commons.Response;
import com.leinao.constant.*;
import com.leinao.file.dto.FilePageDto;
import com.leinao.file.service.BusinessFileService;
import com.leinao.login.dto.LoginResultDto;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 *
 * @Description 文件下载控制类
 * @author lizi
 * @date 2018/10/16 上午11:19
 * @Version 1.0
 */
@RestController
@CrossOrigin
public class BusinessFileController {
    private static Logger logger = LoggerFactory.getLogger(BusinessFileController.class);

    @Autowired
    private BusinessFileService businessFileService;

    @Autowired
    private HttpServletRequest request;

    @ApiOperation(value="项目创建仓库初始化", notes="项目创建仓库初始化")
    @PostMapping(value = "/file/project/initRepository")
    public Response<String> initRepository(@ApiParam(value = "项目名称", required = true) @RequestParam String projectName,
                                           @ApiParam(value = "时间戳", required = true) @RequestParam String timestamp) {
        logger.info("initRepository param projectName: {}, timestamp: {}", projectName, timestamp);

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        return businessFileService.initRepository(projectName, timestamp, userInfo);
    }

    @ApiOperation(value="项目仓库代码克隆", notes="项目仓库代码克隆")
    @PostMapping(value = "/file/project/cloneRepository")
    public Response<String> copyProjectFile(@ApiParam(value = "项目ID", required = true) @RequestParam Long projectId,
                                            @ApiParam(value = "拷贝后的项目名称", required = true) @RequestParam String projectName,
                                            @ApiParam(value = "时间戳", required = true) @RequestParam String timestamp,
                                            @ApiParam(value = "最大任务标签", required = true) @RequestParam String maxTag,
                                            @ApiParam(value = "任务标签，多个逗号隔开", required = true) @RequestParam String tags) {
        logger.info("cloneRepository param projectId: {}, projectName: {}, timestamp: {}, maxTag: {}, tags: {}", projectId, projectName, timestamp, maxTag, tags);

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        return businessFileService.cloneRepository(projectId, projectName, timestamp, maxTag ,tags, userInfo);
    }

    @ApiOperation(value="提交任务仓库代码打标签", notes="提交任务仓库代码打标签")
    @PostMapping(value = "/file/job/initTag")
    public Response<String> fileJobInitTag(@ApiParam(value = "项目ID", required = true) @RequestParam Long projectId,
                                           @ApiParam(value = "标签号", required = true) @RequestParam String tag) {
        logger.info("fileJobInitTag param projectId: {}, tag: {}", projectId, tag);

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        return businessFileService.addTag(projectId, tag, userInfo);
    }

    @ApiOperation(value="获取公开项目文件列表", notes="返回公开项目文件列表")
    @GetMapping(value = "/file/getPublicProjectFileList")
    public Response<FilePageDto> getPublicProjectFileList(@ApiParam(value = "公开任务ID", required = true) @RequestParam Long projectId,
                                                          @ApiParam(value = "以/开头", required = true) @RequestParam String dir,
                                                          @ApiParam(value = "当前页") @RequestParam(required = false) Integer pageNumber,
                                                          @ApiParam(value = "每业条数") @RequestParam(required = false) Integer pageSize) {
        logger.info("getPublicProjectFileList param dir: {}, projectId: {}, pageNumber: {}, pageSize: {}", dir, projectId, pageNumber, pageSize);

        // 默认分页条件设置
        pageNumber = pageNumber == null || pageNumber < 1 ? Constant.DEFAULT_PAGE_NUMBER : pageNumber;
        pageSize = pageSize == null || pageSize < 1 ? Constant.DEFAULT_PAGE_SIZE : pageSize;

        return businessFileService.getPublicProjectFileList(projectId, dir, pageNumber, pageSize);
    }

    @ApiOperation(value="获取公开任务文件列表", notes="返回公开任务文件列表")
    @GetMapping(value = "/file/getPublicProjectJobFileList")
    public Response<FilePageDto> getPublicProjectJobFileList(@ApiParam(value = "公开任务ID", required = true) @RequestParam Long projectPublicJobId,
                                                             @ApiParam(value = "以/开头", required = true) @RequestParam String dir,
                                                             @ApiParam(value = "当前页") @RequestParam(required = false) Integer pageNumber,
                                                             @ApiParam(value = "每业条数") @RequestParam(required = false) Integer pageSize) {
        logger.info("getPublicProjectFileList param dir: {}, projectPublicJobId: {}, pageNumber: {}, pageSize: {}", dir, projectPublicJobId, pageNumber, pageSize);

        // 默认分页条件设置
        pageNumber = pageNumber == null || pageNumber < 1 ? Constant.DEFAULT_PAGE_NUMBER : pageNumber;
        pageSize = pageSize == null || pageSize < 1 ? Constant.DEFAULT_PAGE_SIZE : pageSize;

        return businessFileService.getProjectPublicJobFileList(projectPublicJobId, dir, pageNumber, pageSize);
    }

    @ApiOperation(value="获取个人任务文件列表", notes="返回个人任务文件列表")
    @GetMapping(value = "/file/getProjectJobFileList")
    public Response<FilePageDto> getProjectJobFileList(@ApiParam(value = "任务ID", required = true) @RequestParam Long projectJobId,
                                                       @ApiParam(value = "以/开头", required = true) @RequestParam String dir,
                                                       @ApiParam(value = "当前页") @RequestParam(required = false) Integer pageNumber,
                                                       @ApiParam(value = "每业条数") @RequestParam(required = false) Integer pageSize) {
        logger.info("getProjectJobFileList param projectJobId: {}, dir: {}, pageNumber: {}, pageSize: {}", projectJobId, dir, pageNumber, pageSize);

        // 默认分页条件设置
        pageNumber = pageNumber == null || pageNumber < 1 ? Constant.DEFAULT_PAGE_NUMBER : pageNumber;
        pageSize = pageSize == null || pageSize < 1 ? Constant.DEFAULT_PAGE_SIZE : pageSize;

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        return businessFileService.getProjectJobFileList(projectJobId, dir, pageNumber, pageSize, userInfo);
    }

    @ApiOperation(value="公开项目文件预览", notes="公开项目文件预览")
    @GetMapping(value = "/file/publicProjectFile/preview")
    public void previewPublicProjectFile(@ApiParam(value = "项目ID", required = true) @RequestParam Long projectId,
                                         @ApiParam(value = "文件路径", required = true) @RequestParam String dir,
                                         HttpServletResponse response) {
        logger.info("previewPublicProjectFile param projectId: {},  dir: {}", projectId, dir);

        // 预览文件
        businessFileService.previewPublicProjectFile(projectId, dir, response);
    }

    @ApiOperation(value="公开任务文件预览", notes="公开任务文件预览")
    @GetMapping(value = "/file/publicProjectJobFile/preview")
    public void previewPublicProjectJobFile(@ApiParam(value = "公开任务ID", required = true) @RequestParam Long projectPublicJobId,
                                            @ApiParam(value = "文件路径", required = true) @RequestParam String dir,
                                            HttpServletResponse response) {
        logger.info("previewPublicProjectJobFile param projectPublicJobId: {},  dir: {}", projectPublicJobId, dir);

        // 预览文件
        businessFileService.previewPublicProjectJobFile(projectPublicJobId, dir, response);
    }

    @ApiOperation(value="任务文件预览", notes="任务文件预览")
    @GetMapping(value = "/file/projectJobFile/preview")
    public void previewProjectJobFile(@ApiParam(value = "任务ID", required = true) @RequestParam Long projectJobId,
                                      @ApiParam(value = "文件路径", required = true) @RequestParam String dir,
                                      HttpServletResponse response) {
        logger.info("previewProjectJobFile param projectJobId: {},  dir: {}", projectJobId, dir);

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        // 预览文件
        businessFileService.previewProjectJobFile(projectJobId, dir, userInfo, response);
    }



    @ApiOperation(value="公开项目文件下载", notes="公开项目文件预览")
    @GetMapping(value = "/file/publicProjectFile/download")
    public void downloadPublicProjectFile(@ApiParam(value = "项目ID", required = true) @RequestParam Long projectId,
                                          @ApiParam(value = "文件路径", required = true) @RequestParam String[] dirs,
                                          HttpServletResponse response) {
        logger.info("downloadPublicProjectFile param projectId: {},  dirs: {}", projectId, dirs);

        // 下载文件
        businessFileService.downloadPublicProjectFile(projectId, dirs, response);
    }

    @ApiOperation(value="公开任务文件下载", notes="公开任务文件下载")
    @GetMapping(value = "/file/publicProjectJobFile/download")
    public void downloadPublicProjectJobFile(@ApiParam(value = "公开任务ID", required = true) @RequestParam Long projectPublicJobId,
                                             @ApiParam(value = "文件路径", required = true) @RequestParam String[] dirs,
                                             HttpServletResponse response) {
        logger.info("downloadPublicProjectJobFile param projectPublicJobId: {},  dirs: {}", projectPublicJobId, dirs);

        // 下载文件
        businessFileService.downloadPublicProjectJobFile(projectPublicJobId, dirs, response);
    }

    @ApiOperation(value="任务文件下载", notes="任务文件下载")
    @GetMapping(value = "/file/projectJobFile/download")
    public void downloadProjectJobFile(@ApiParam(value = "任务ID", required = true) @RequestParam Long projectJobId,
                                       @ApiParam(value = "文件路径", required = true) @RequestParam String[] dirs,
                                       HttpServletResponse response) {
        logger.info("downloadProjectJobFile param projectJobId: {},  dirs: {}", projectJobId, dirs);

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        // 下载文件
        businessFileService.downloadProjectJobFile(projectJobId, dirs, userInfo, response);
    }

    @ApiOperation(value="获取公开数据集文件列表", notes="返回公开数据集文件列表")
    @GetMapping(value = "/file/getPublicDatasetFileList")
    public Response<FilePageDto> getPublicDatasetFileList(@ApiParam(value = "数据集编号", required = true) @RequestParam String number) {
        logger.info("getPublicDatasetFileList param number: {}", number);

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        return businessFileService.getPublicDatasetFileList(userInfo.getUserId(), number);
    }

    @ApiOperation(value="公开数据集文件预览", notes="公开数据集文件预览")
    @GetMapping(value = "/file/publicDatasetFile/preview")
    public void previewPublicDatasetFile(@ApiParam(value = "数据集编号", required = true) @RequestParam String number,
                                         @ApiParam(value = "文件路径", required = true) @RequestParam String path,
                                         HttpServletResponse response) {
        logger.info("previewPublicDatasetFile param number: {},  path: {}", number, path);

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        // 下载文件
        businessFileService.previewPublicDatasetFile(userInfo.getUserId(), number, path, response);
    }

    @ApiOperation(value="创建任务输出目录", notes="创建任务输出目录")
    @PostMapping(value = "/file/job/createOutputs")
    public Response<String> createJobOutputs(@ApiParam(value = "项目ID", required = true) @RequestParam Long projectId,
                                             @ApiParam(value = "任务编号", required = true) @RequestParam Integer jobNumber) {
        logger.info("createJobOutputs param projectId: {}, jobNumber: {}", projectId, jobNumber);

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        return businessFileService.createJobOutputs(userInfo.getUserId(), projectId, jobNumber);
    }

    @ApiOperation(value="复制output文件到数据集文件目录", notes="数据集公开给个人用户列表")
    @GetMapping(value = "/copyOutputFile")
    public Response<Void> copyOutputFile(
            @ApiParam(value = "项目ID", required = true) @RequestParam Long projectId,
            @ApiParam(value = "任务名称", required = true) @RequestParam String jobName,
            @ApiParam(value = "目录", required = true) @RequestParam String dir,
            HttpServletRequest request) {

        logger.info("copyOutputFile param: projectId is {}, jobName is {}, dir: {}", projectId, jobName, dir);
        logger.info("searchPublicDataSetList param: projectId is {}, jobName is {}, dir: {}", projectId, jobName, dir);

        if(null == projectId){
            return Response.error(Constant.SUCCESS_CODE, DataSetErrorEnum.DATASET_PROJECT_ID_IS_EMTPY_ERROR.getSeq(),
                    DataSetErrorEnum.DATASET_PROJECT_ID_IS_EMTPY_ERROR.getDesc(), null);
        }

        if(StringUtils.isBlank(jobName)){
            return Response.error(Constant.SUCCESS_CODE, DataSetErrorEnum.DATASET_JOB_NAME_IS_EMTPY_ERROR.getSeq(),
                    DataSetErrorEnum.DATASET_JOB_NAME_IS_EMTPY_ERROR.getDesc(), null);
        }

        if(StringUtils.isBlank(dir)){
            return Response.error(Constant.SUCCESS_CODE, DataSetErrorEnum.DATASET_DIR_IS_EMPTY.getSeq(),
                    DataSetErrorEnum.DATASET_DIR_IS_EMPTY.getDesc(), null);
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.ok(Constant.SUCCESS_CODE, DataSetErrorEnum.GET_DATASET_ERROR.getSeq(), DataSetErrorEnum.GET_DATASET_ERROR.getDesc(), null);
        }

        return businessFileService.copyOutputFile(projectId, jobName, dir, userInfo);
    }

    @ApiOperation(value="获取项目-任务输出output目录", notes="查看任务详情，output目录")
    @GetMapping(value = "/file/getJobOutPutFileList")
    public Response<FilePageDto> getJobOutPutFileList(@ApiParam(value = "项目id", required = true) @RequestParam Long projectId,
                                                      @ApiParam(value = "任务名", required = true) @RequestParam String jobName,
                                                      @ApiParam(value = "目录,只传userhome后的目录即可，以/开头", required = true) @RequestParam String dir,
                                                      @ApiParam(value = "当前页") @RequestParam(required = false) Integer pageNumber,
                                                      @ApiParam(value = "每业条数") @RequestParam(required = false) Integer pageSize) {

        logger.info("getJobOutPutFileList param projectId : {},jobName:{}, dir: {}, pageNumber: {}, pageSize: {}", projectId,jobName , dir, pageNumber, pageSize);

        // 默认分页条件设置
        if(pageNumber == null || pageNumber < 1) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }
        if(pageSize == null || pageSize < 1) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        return businessFileService.getJobOutPutFileList(userInfo.getUserId(),projectId,jobName , dir, pageNumber, pageSize);
    }

    @ApiOperation(value="任务output中文件下载", notes="任务详情-文件下载")
    @GetMapping(value = "/file/jobOutputFileDownload")
    public void jobOutputFileDownload(@ApiParam(value = "任务名") @RequestParam String jobName,
                                      @ApiParam(value = "项目id", required = true) @RequestParam Long projectId,
                                      @ApiParam(value = "目录名", required = true) @RequestParam String[] dirs,
                                      HttpServletResponse response) {
        logger.info("download param jobName : {}, dirs: {},projectId:{}", jobName, Arrays.toString(dirs),projectId);

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        // 下载文件
        businessFileService.jobOutputFileDownload(userInfo.getUserId(), projectId,jobName, dirs, response);
    }

    @ApiOperation(value="获取公开项目-任务输出output目录", notes="查看公开任务详情，output目录")
    @GetMapping(value = "/file/getPublicJobOutPutFileList")
    public Response<FilePageDto> getPublicJobOutPutFileList(@ApiParam(value = "公开项目id", required = true) @RequestParam Long projectId,
                                                            @ApiParam(value = "任务名", required = true) @RequestParam String jobName,
                                                            @ApiParam(value = "目录,只传userhome后的目录即可，以/开头", required = true) @RequestParam String dir,
                                                            @ApiParam(value = "当前页") @RequestParam(required = false) Integer pageNumber,
                                                            @ApiParam(value = "每业条数") @RequestParam(required = false) Integer pageSize) {

        logger.info("getPublicJobOutPutFileList param projectId : {},jobName:{}, dir: {}, pageNumber: {}, pageSize: {}", projectId,jobName , dir, pageNumber, pageSize);

        // 默认分页条件设置
        if(pageNumber == null || pageNumber < 1) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }
        if(pageSize == null || pageSize < 1) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );

        return businessFileService.getPublicJobOutPutFileList(userInfo.getUserId(),projectId,jobName , dir, pageNumber, pageSize);
    }

    @ApiOperation(value="任务output中文件预览", notes="任务详情-output文件预览")
    @GetMapping(value = "/file/jobOutput/preview")
    public void previewJobOutputFile(@ApiParam(value = "项目ID", required = true) @RequestParam Long projectId,
                                     @ApiParam(value = "任务名", required = true) @RequestParam String jobName,
                                         @ApiParam(value = "文件路径", required = true) @RequestParam String dir,
                                         HttpServletResponse response) {
        logger.info("previewPublicProjectFile param projectId: {}, jobName: {}, dir: {}", projectId,jobName, dir);

        // 预览文件
        businessFileService.previewJobOutputFile(projectId,jobName,dir, response);
    }

    @ApiOperation(value="公开任务 output中文件预览", notes="公开任务详情-output文件预览")
    @GetMapping(value = "/file/publicJobOutput/preview")
    public void previewPublicJobOutputFile(@ApiParam(value = "项目ID", required = true) @RequestParam Long projectId,
                                     @ApiParam(value = "任务名", required = true) @RequestParam String jobName,
                                     @ApiParam(value = "文件路径", required = true) @RequestParam String dir,
                                     HttpServletResponse response) {
        logger.info("previewPublicProjectFile param projectId: {}, jobName: {}, dir: {}", projectId,jobName, dir);

        // 预览文件
        businessFileService.previewPublicJobOutputFile(projectId,jobName,dir, response);
    }

    @ApiOperation(value="复制output文件到模型文件目录", notes="新建模型使用用户任务output")
    @PostMapping(value = "/file/copyOutputFileForModel")
    public Response<Void> copyOutputFileForModel(
            //String projectName, Integer codeNo, String modelName
            @ApiParam(value = "项目名称", required = true) @RequestParam String projectName,
            @ApiParam(value = "任务编号", required = true) @RequestParam Integer codeNo,
            @ApiParam(value = "模型名称", required = true) @RequestParam String modelName,
            HttpServletRequest request) {

        logger.info("copyOutputFileForModel param: projectName is {}, codeNo is {}, modelName: {}", projectName, codeNo, modelName);

        if(null == codeNo){
            return Response.error(Constant.SUCCESS_CODE,ModelErrorEnum.CODENO_IS_EMPTY_ERROR.getSeq(),
                    ModelErrorEnum.CODENO_IS_EMPTY_ERROR.getDesc(), null);
        }

        if(StringUtils.isBlank(projectName)){
            return Response.error(Constant.SUCCESS_CODE, ModelErrorEnum.PROJECTNAME_IS_EMPTY_ERROR.getSeq(),
                    ModelErrorEnum.PROJECTNAME_IS_EMPTY_ERROR.getDesc(), null);
        }

        if(StringUtils.isBlank(modelName)){
            return Response.error(Constant.SUCCESS_CODE, ModelErrorEnum.MODELNAME_IS_EMPTY_ERROR.getSeq(),
                    ModelErrorEnum.MODELNAME_IS_EMPTY_ERROR.getDesc(), null);
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.ok(Constant.SUCCESS_CODE, DataSetErrorEnum.GET_DATASET_ERROR.getSeq(), DataSetErrorEnum.GET_DATASET_ERROR.getDesc(), null);
        }

        return businessFileService.copyOutputFileForModel(projectName,codeNo,userInfo.getUserId(),modelName);
    }

    @ApiOperation(value="获取1.0用户文件列表", notes="数据迁移页面使用")
    @GetMapping(value = "/file/getUserHomeFileList")
    public Response<FilePageDto> getUserHomeFileList(@ApiParam(value = "当前页") @RequestParam(required = false) Integer pageNumber,
                                                          @ApiParam(value = "每页条数") @RequestParam(required = false) Integer pageSize) {
        logger.info("getUserHomeFileList param pageNumber: {}, pageSize: {}", pageNumber, pageSize);

        // 默认分页条件设置
        if(pageNumber == null || pageNumber < Constant.DEFAULT_PAGE_NUMBER) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }

        if(pageSize == null || pageSize < Constant.DEFAULT_PAGE_NUMBER) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        //获取用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.ok(Constant.SUCCESS_CODE, DataSetErrorEnum.GET_DATASET_ERROR.getSeq(), DataSetErrorEnum.GET_DATASET_ERROR.getDesc(), null);
        }

        return businessFileService.getUserHomeFileList(userInfo, pageNumber, pageSize);
    }

    @ApiOperation(value="1.0数据迁移,保存为数据集/模型", notes="数据迁移页面使用")
    @GetMapping(value = "/file/copyFilesToDataSetOrModel")
    public Response<String> copyFilesToDataSetOrModel(@ApiParam(value = "勾选目录名", required = true) @RequestParam String[] dirs,
                                             @ApiParam(value = "生成结果类型  1：数据集  2：模型", required = true) @RequestParam Integer type,
                                             @ApiParam(value = "生成模型/数据集名称", required = true) @RequestParam String targetDir,
                                             HttpServletRequest request) {
        logger.info("copyFilesToDataSetOrModel param dirs: {}, type: {}, targetDir: {}", Arrays.toString(dirs), type, targetDir);

        //校验生成结果类型
        if(!type.equals(Constant.DATASET_TYPE) && !type.equals(Constant.MODEL_TYPE)){
            return Response.ok(Constant.SUCCESS_CODE,
                    FileErrorEnum.FILE_TYPE_ERROR.getSeq(), FileErrorEnum.FILE_TYPE_ERROR.getDesc(), null);
        }

        //获取用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return businessFileService.copyFilesToDataSetOrModel(userInfo, dirs, type, targetDir);
    }

}
